package com.iwop.moto.controller;

import com.iwop.moto.auth.LoginAuth;
import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.MBankAccount;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.MBankAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.UUID;

/**
 * Created by mobom on 2016/9/29.
 */
@Controller
public class MBankAccountController extends BaseController {
    @Autowired
    private MBankAccountService mBankAccountService;

    @RequestMapping("/api/bank/account/add")
    @ResponseBody
    @LoginAuth(isval=true)
    public ResultModel bankAccountAdd(@ModelAttribute MBankAccount mBankAccount,HttpServletRequest request){
        mBankAccount.setSid(UUID.randomUUID().toString());
        mBankAccount.setStatusTime(new Date());
        mBankAccount.setUserId(request.getParameter("session_id"));
        try {
            mBankAccountService.insertMBankAccount(mBankAccount);
            return getSucceed(ErrCode.SUCCEED);
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

    @RequestMapping("/api/bank/account/get")
    @ResponseBody
    @LoginAuth(isval=true)
    public ResultModel bankAccountEdit(@ModelAttribute MBankAccount mBankAccount,HttpServletRequest request){
        SuperRecordModel superRecordModel=new SuperRecordModel();
        superRecordModel.put("userId",request.getParameter("session_id"));
        return getSucceed(mBankAccountService.getMBankAccount(superRecordModel));
    }
}
